package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.cultureEnterprise.CultureEnterpriseExportDto;
import com.lnking.lnkingplace.model.dto.garden.GardenExportDto;
import com.lnking.lnkingplace.model.entity.CultureEnterprise;
import com.lnking.lnkingplace.model.entity.Garden;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureSearchRequest;
import com.lnking.lnkingplace.model.request.garden.GardenAddRequest;
import com.lnking.lnkingplace.model.request.garden.GardenSearchRequest;
import com.lnking.lnkingplace.model.request.garden.GardenUpdateRequest;
import com.lnking.lnkingplace.service.IGardenService;
import com.lnking.starter.export.utils.ExportUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-10-03
 */
@RestController
@RequestMapping("/garden")
@Api(tags = "文创园区管理")
public class GardenController {

    @Resource
    IGardenService gardenService;

    @ApiOperation("查询")
    @GetMapping("list")
    public ReturnResult getList(GardenSearchRequest params){
        return ReturnResult.success(gardenService.pageList(params));
    }

    @ApiOperation("新增")
    @PostMapping("add")
    public ReturnResult add(@Valid @RequestBody GardenAddRequest params){
        gardenService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public ReturnResult update(@Valid @RequestBody GardenUpdateRequest params){
        gardenService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询详情")
    @GetMapping("get-details")
    public ReturnResult getDetails(String id){
        return ReturnResult.success(gardenService.getById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        gardenService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("导入")
    @PostMapping("import")
    private ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception{
        gardenService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation(value = "导出")
    @GetMapping(value = "/export")
    public void exportInfo(GardenSearchRequest params, HttpServletResponse response) throws Exception {
        List<Garden> data = (List<Garden>) gardenService.pageList(params);
        ExportUtils.export(data, response, GardenExportDto.class);
    }
}
